﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SH.STD.Model;
using SH.STD.DataProvider;

namespace SH.STD.Web.Admin
{
    public partial class ProjectTypeList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                this.Master.SetTab(TabType.Admin);
                var sql = @"
select a.ID,a.Name,b.Name as ParentName,a.Memo,a.LastModifiedBy 
from ProjectType a
left join ProjectType b
on a.ParentID=b.ID
where a.status=1
order by a.ID";

                this.BindData(sql);
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            var sql = @"
select a.ID,a.Name,b.Name as ParentName,a.Memo,a.LastModifiedBy 
from ProjectType a
left join ProjectType b
on a.ParentID=b.ID
where a.status=1 and a.Name like '%" + txtName.Text.Trim() + @"%'
order by a.ID";
            this.BindData(sql);
        }

        private void BindData(string sql)
        {
            var datas = DataAccess.GetDataTable(sql);
            this.rptTypes.DataSource = datas;
            this.rptTypes.DataBind();

            this.lblCnt1.Text = datas.Rows.Count.ToString();
        }

        protected void btnClear_Click(object sender, EventArgs e)
        {
            this.txtName.Text = String.Empty;
            var sql = @"
select a.ID,a.Name,b.Name as ParentName,a.Memo,a.LastModifiedBy 
from ProjectType a
left join ProjectType b
on a.ParentID=b.ID
where a.status=1
order by a.ID";

            this.BindData(sql);
        }
    }
}